﻿import React from 'react';
import {Link, hashHistory } from 'react-router';
import { Icon,  Table, Spin, Button } from 'antd';
import classNames from 'classnames';
import {connect} from 'react-redux'
import SearchInput from '../../components/SearchInput'
import { ordersQuery } from '../../actions'
import './index.css'

class OrderCheckList extends React.Component {

	constructor(props){
		super(props);
	}

  componentWillMount () {
    console.log('OrderCheckList.componentWillMount')
    //发起待审核信息查询
    this.props.dispatch(ordersQuery.request()());
  }

	onAdvancedSearchClick() {
	}

	onSelectChange(selectedRowKeys) {
	}

	onStudentDetailClick(id) {

  }

  orderDetailClick(id, studentId) {
    hashHistory.push({ pathname: '/order/checkOne', state: { id, studentId, mode:'Edit', back:'/order/check' } });
  }

  onReloadClick() {
    this.props.dispatch(ordersQuery.request()());
  }

	render() {
		let { orders, loading=false } = this.props;

    console.log(orders, this.props);
    const orderCheckColumns = [
      {
        title: '学号',
        dataIndex: 'studentId',
        width: '10%',
      },
      {
        title: '姓名',
        dataIndex: 'name',
        width: '5%',
      },
      {
        title: '专业',
        dataIndex: 'majorName',
        width: '25%',
      },
      {
        title: '手机',
        dataIndex: 'mobile',
        width: '10%',
      },
      {
        title: '单位名称',
        dataIndex: 'companyName',
        width: '25%',
      },
      {
        title: '单位联系电话',
        dataIndex: 'companyTelephone',
        width: '10%'
      },
      {
        title: '申请时间',
        dataIndex: 'createdDate',
        width: '10%'
      },
      {
        title: '操作',
        key: 'operation',
        render:(text, record) => (
          <Button onClick={this.orderDetailClick.bind(this, record.id, record.studentId)} >查看</Button>
        ),
        width: '5%'
      }
    ];
		// 表格的列控制
		return (
			<div>
        <div style={{ marginTop: 24, marginBottom: 16 }} className="clearfix">
          <div className="pull-left">
            <Button type="primary" icon="reload" onClick={this.onReloadClick.bind(this)}>刷新</Button>
          </div>
          <div className="pull-right">
            <SearchInput placeholder="请输入学号" onSearch={value => console.log(value)} style={{ width: 200 }} />
            <a style={{marginLeft:8}} onClick={this.onAdvancedSearchClick.bind(this)} type="primary" >高级搜索</a></div>
        </div>
        <Spin spinning={loading}><Table columns={orderCheckColumns} dataSource={orders} /></Spin>
			</div>
		);
	}
}

function mapStateToProps(state) {
  return {
    orders: state.order.orders,
    loading:state.order.loading,
  };
}

export default connect(mapStateToProps)(OrderCheckList)
